﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modellayer;
using Dblayer;

namespace ControlLayer
{
    public class PersonCtr
    {
        DbPerson dbPerson;
        private static PersonCtr instance;

        private PersonCtr()
        {
            dbPerson = new DbPerson();
        }

        public static PersonCtr getInstance()
        {
            if (instance == null)
            {
                instance = new PersonCtr();
            }
            return instance;
        }

        public void createEmployee(int phoneNumber, string email, string password, string name, string loginId)
        {
            Person person = new Person(phoneNumber, email, password, name, loginId, "Employee");
            dbPerson.createPerson(person);
        }

        public void createCustomer(int phoneNumber, string email, string password, string name)
        {
            Person person = new Person(phoneNumber, email, password, name, null, "Customer");
            dbPerson.createPerson(person);
        }

        public Person findPerson(int phoneNumber)
        {
            return dbPerson.findPerson(phoneNumber);
        }

        public Person findPersonByLoginIdAndPassword(string loginId, string password)
        {
            return dbPerson.findPersonByLoginIdAndPassword(loginId, password);
        }

        public void updatePerson(int phoneNumber, string name, string email, string password)
        {
            Person person = new Person(phoneNumber, email, password, name, "", "");
            dbPerson.updatePerson(person);
        }

        public void deletePerson(int phoneNumber)
        {
            dbPerson.deletePerson(phoneNumber);
        }
    }
}
